package com.example.wly.application_3_homework;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.wly.application_3_homework.bean.WeaponInfo;

public class ShopActivity extends AppCompatActivity {
    WeaponInfo weaponInfo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);
        //1-初始化武器文本框的值
        weaponInfo=new WeaponInfo(20,100,30);
        TextView tvWeapon=(TextView)findViewById(R.id.tv_shop_weapon);
        tvWeapon.setText("生命值：+"+weaponInfo.getLife());
        tvWeapon.append("\n攻击力：+"+weaponInfo.getAttak());
        tvWeapon.append("\n敏捷度：+"+weaponInfo.getSpeed());
        //2-返回详情页，带回这个武器值---点击武器条目，返回
        LinearLayout llWeaponItem=(LinearLayout)findViewById(R.id.ll_weapon_item);
        llWeaponItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //将数据带回
                Intent intent=new Intent();
                //对数据的序列化，将对象的属性转换成byte[]，之后进行传输
                intent.putExtra("weapon",weaponInfo);
                //startActivity(intent);
                setResult(2,intent);
                finish();
            }
        });
    }
}
